require "common/Define"
require "framework/BaseController"
require "FairyGUI"

ModelMain = BaseController:New({mControllerName = "ModelMain"});

function ModelMain.Main()
	-- body
	ModelMain:Awake();
end

function ModelMain:Awake()
	Application.targetFrameRate = 60;
	Stage.inst.onKeyDown:Add(self.OnKeyDown, self);

	-- attack pacakge, package in resource or assetbundle
	local packageName = "UI/Model";
	UIPackage.AddPackage(packageName);

	local componentName = "Main";
	self.mainComponent = UIPackage.CreateObject("Model", componentName).asCom;
	GRoot.inst:AddChild( self.mainComponent );

	GRoot.inst:SetContentScaleFactor(1134, 640, FairyGUI.UIContentScaler.ScreenMatchMode.MatchWidthOrHeight);

	self:OnViewCreated(self.mainComponent);

end

function ModelMain:InitView()
	-- body
	local prefab = Resources.Load("Role/npc");
	local go = GameObject.Instantiate(prefab);
	go.transform.localPosition = Vector3(61, -89, 1000); -- set z to far from UICamera is important!
	go.transform.localScale = Vector3(180, 180, 180);
	go.transform.localEulerAngles = Vector3(0, 100, 0);
	self.mainComponent:GetChild("holder").asGraph:SetNativeObject( FairyGUI.GoWrapper(go) );
end

function ModelMain:OnKeyDown(context)
	if (context.inputEvent.keyCode == KeyCode.Escape) then
		Application.Quit();
	end
end